package org.jiuling.aliyun.oss.spring.config;

import org.jiuling.aliyun.config.AliYunConfig;
import org.jiuling.aliyun.oss.operation.AliYunBucketOperation;
import org.jiuling.aliyun.oss.operation.AliYunObjectOperation;
import org.jiuling.aliyun.oss.client.build.AliYunOssClientBuilder;
import org.jiuling.aliyun.oss.client.factory.AliYunOssClientFactory;
import org.jiuling.aliyun.oss.config.AliYunOssConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云对象存储Bean配置
 * @author 紫灵
 * @date 2024年06月22日 17时23分46秒
 */
@Configuration
public class AliYunOssSpringBeanConfig {

    private final AliYunConfig aliYunConfig;

    public AliYunOssSpringBeanConfig(AliYunConfig aliYunConfig) {
        this.aliYunConfig = aliYunConfig;
    }

    @Bean
    @ConfigurationProperties(prefix = "jiu-ling.aliyun.cos")
    public AliYunOssConfig aliYunOssConfig(){
        return new AliYunOssConfig();
    }

    @Bean
    public AliYunOssClientFactory aliYunOssClientFactory(){
        return new AliYunOssClientBuilder(aliYunOssConfig(),aliYunConfig);
    }

    @Bean
    public AliYunBucketOperation aliYunBucketOperation(){
        return new AliYunBucketOperation(aliYunOssClientFactory());
    }

    @Bean
    public AliYunObjectOperation aliYunObjectOperation(){
        return new AliYunObjectOperation(aliYunOssClientFactory());
    }

}
